from rest_framework import serializers
from .models import User, Technician

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'username', 'openid', 'role', 'phone', 'avatar', 'created_at', 'updated_at']
        read_only_fields = ['id', 'openid', 'created_at', 'updated_at']


class TechnicianSerializer(serializers.ModelSerializer):
    user = UserSerializer(read_only=True)
    
    class Meta:
        model = Technician
        fields = '__all__'
        read_only_fields = ['id', 'created_at', 'updated_at']


class WeChatLoginSerializer(serializers.Serializer):
    code = serializers.CharField(max_length=100)
    nickname = serializers.CharField(max_length=100, required=False)
    avatar = serializers.URLField(required=False)
    encrypted_data = serializers.CharField(required=False)
    iv = serializers.CharField(required=False)


class TechnicianCertificationSerializer(serializers.ModelSerializer):
    class Meta:
        model = Technician
        fields = ['real_name', 'id_card', 'service_area', 'experience', 'id_card_front', 'id_card_back', 'certification']